package top.component;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import top.pojo.MaketTwo;
import top.pojo.Source;

import javax.sql.DataSource;
import java.util.Properties;

@Data
@Component
public class ComponentController {
    @Autowired
    private Source source ;

    @Autowired
    private ExampleCase exampleCase;

    @Autowired
    @Qualifier("componentCase")
    private ComponentInter con;

    @Bean
    public static DataSource getDataSource(){
        Properties properties = new Properties();
        properties.setProperty("driver", "com.mysql.jdbc.Driver");
        properties.setProperty("url", "jdbc:mysql://localhost:3306/rwxbase");
        properties.setProperty("username", "root");
        properties.setProperty("password", "admin");
        DataSource dataSource = null;
        try {
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }

    @Bean(initMethod = "init" ,destroyMethod = "destroy",name = "maketTwo")
    public MaketTwo getMaketTwo() {
        MaketTwo maketTwo = new MaketTwo();
        maketTwo.setBeverageShop("设计的佛i时间佛i时间");
        Source source = new Source();
        source.setFruit("香蕉");
        source.setSize("超级打");
        maketTwo.setSource(source);
        return maketTwo;
    }
}
